﻿<%@ Page Language="C#" MasterPageFile="~/Site.master" CodeBehind="Insert.aspx.cs" Inherits="Fatec.ControleEstoque.Interface.Insert_Pedidos" %>

<%@ Register Assembly="System.Web.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System.Web.UI.WebControls" tagprefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true" />

    <h2>Adicionar novo registro em <%= table.DisplayName %></h2>

    <asp:ScriptManagerProxy runat="server" ID="ScriptManagerProxy1" />

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
                HeaderText="Lista de erros de validação" />
            <asp:DynamicValidator runat="server" ID="DetailsViewValidator" ControlToValidate="DetailsView1" Display="None" />

            <asp:DetailsView ID="DetailsView1" runat="server" 
                DataSourceID="DetailsDataSource" DefaultMode="Insert"
                AutoGenerateInsertButton="True" OnItemCommand="DetailsView1_ItemCommand" OnItemInserted="DetailsView1_ItemInserted"
                CssClass="detailstable" FieldHeaderStyle-CssClass="bold" 
                ondatabound="DetailsView1_DataBound">
            </asp:DetailsView>
            
            <br />

            <asp:GridView ID="GridView1" runat="server"
                AutoGenerateDeleteButton="True" 
                CssClass="gridview" DataSourceID="ObjectDataSource1" 
                onrowcreated="GridView1_RowCreated" AutoGenerateColumns="False" 
                AutoGenerateEditButton="True">
                <Columns>
                    <asp:DynamicField DataField="Qtde" HeaderText="Qtde" />
                    <asp:DynamicField DataField="Valor" HeaderText="Valor" />
                    <asp:DynamicField DataField="Produto" HeaderText="Produto" />
                </Columns>
            </asp:GridView>

            <br />
         
            <div class="bottomhyperlink">
                <asp:LinkButton ID="LinkButtonInsert" runat="server" onclick="LinkButtonInsert_Click" CausesValidation="False">Inserir Produto</asp:LinkButton>
            </div>
            
            <br />
                        
            <asp:Panel ID="DetailsPanel" runat="server" style="display:block">
                <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <asp:Button id="ButtonShowPopup" runat="server" style="display:none" />
        		        <ajx:ModalPopupExtender ID="ModalPopupExtender1" runat="server" 
        		            TargetControlID="ButtonShowPopup" PopupControlID="DetailsPanel" 
        		            CancelControlID="LinkButtonCancel" BackgroundCssClass="modalBackground"	/>
                    
                        <asp:ValidationSummary ID="ValidationSummary2" runat="server" EnableClientScript="true" HeaderText="Lista de erros de validação" ShowMessageBox="true" ShowSummary="false" />
                        <asp:DynamicValidator runat="server" ID="DynamicValidator2" ControlToValidate="DetailsView2" Display="None" />
                        
                        <asp:DetailsView ID="DetailsView2" runat="server" DataSourceID="ObjectDataSource1"
                          CssClass="detailstable" FieldHeaderStyle-CssClass="bold" 
                            AutoGenerateRows="False">
                            <FieldHeaderStyle CssClass="bold" />
                            <Fields>
                                <asp:DynamicField DataField="Qtde" HeaderText="Qtde" />
                                <asp:DynamicField DataField="Valor" HeaderText="Valor" />
                                <asp:DynamicField DataField="Produto" HeaderText="Produto" />
                            </Fields>
                        </asp:DetailsView>
                        
                        <asp:LinkButton ID="LinkButtonSave" runat="server" onclick="LinkButtonSave_Click">Salvar</asp:LinkButton>
                        <asp:LinkButton ID="LinkButtonCancel" runat="server" CausesValidation="False">Cancelar</asp:LinkButton>

                    </ContentTemplate>
                </asp:UpdatePanel>
            </asp:Panel>                

            <asp:EntityDataSource ID="DetailsDataSource" runat="server" EnableInsert="true"
              ConnectionString="name=EstoqueEntities" DefaultContainerName="EstoqueEntities" 
              EntitySetName="Pedidos" ondatabinding="DetailsDataSource_DataBinding" 
                oninserted="DetailsDataSource_Inserted">
                <WhereParameters>
                    <asp:DynamicQueryStringParameter />
                </WhereParameters>
            </asp:EntityDataSource>
                               
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
                 DataObjectTypeName="Fatec.ControleEstoque.Data.CustomModel.PedidoItemMetadata"
                 TypeName="Fatec.ControleEstoque.Data.CustomModel.PedidoItem" 
                 InsertMethod="Insert" 
                 SelectMethod="Select" 
                 DeleteMethod="Delete"
                 UpdateMethod="Update"
                 SortParameterName="sortExpression">
            </asp:ObjectDataSource>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
